<?php
 /*
 	The functionalities are:
		1.	Receive the file name
		2.	Save the file name to overwrite_records.txt
		3.	Relink to previous page
 */
$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];
$place=$_POST['myplace'];
$filename=$_POST['myfilename'];
$next=$_POST['mynext'];


if(($myusername=='craig' && $mypassword==123456) || ($myusername=='tony' && $mypassword==654321)) {

    $records_directory = "./record";
    $next_link = $next."#";
    $next_link = $next_link.$place;
    $current_time = time();
    $date = date('m/d/y H:i:s', $current_time);
    $fp = fopen("$records_directory/overwrite_payerintel_records.txt", 'a+');
    fwrite($fp, $filename);
	fwrite($fp, "   overwritten at ");
	fwrite($fp, $date);
	fwrite($fp, " by ");
	fwrite($fp, $myusername);

    fwrite($fp, "\n");
    fclose($fp);
 

    $file = "report.html";
    $lines = file($file);
    $all_lines = implode('',$lines);
    $entry = str_replace("<a href=\"login.php?filename=$filename&next=$next&place=$place\">overwrite</a>",'processing',$all_lines);
    $fp = fopen('tmp.html','w+'); 
    $fw = fwrite($fp,$entry);
    fclose($fp);
    $lastline = system('mv tmp.html report.html',$retval);
 
    if($next) {
    header("location: $next_link");
    } 
    else {
        header("location: report.html");
    }
}
else {
        header("location: login.php?filename=filename=$filename&next=$next&place=$place&failed=1");
}

?>



